from tools.driver import open_dingstock
from unittest import TestCase
from pages.recommend_page import RecommendPage
from pages.mine_page import MinePage
from pages.newest_page import NewestPage
import unittest
from time import sleep
from tools.driver import open_device_atx_server


class TestPublishTrend(TestCase):
    def setUp(self) -> None:
        self.driver = open_dingstock()
        self.recommendpage = RecommendPage(self.driver)
        self.minepage = MinePage(self.driver)
        self.newestpage = NewestPage(self.driver)

    def tearDown(self) -> None:
        sleep(1)

    def test_a_publish_trend(self):
        """测试发布图片动态"""
        trend_content = "测试一下自动发布动态"
        self.recommendpage.click_add_button()
        self.recommendpage.trend_input_text(trend_content)
        self.recommendpage.choose_topic()
        self.recommendpage.choose_image()
        sleep(1)
        self.recommendpage.click_publish()
        content = self.minepage.get_newest_trend_content()
        topic = self.minepage.get_newest_trend_topic()
        assert content == trend_content and topic == "长津湖", "测试发布动态失败"

    def test_b_like_trend(self):
        """测试动态点赞及取消点赞"""
        self.recommendpage.switch_newest()
        origin_like_num = self.newestpage.get_origin_like_num()
        self.newestpage.like_first_trend()
        after_like_num = self.newestpage.get_after_like_num()
        sleep(1)
        self.newestpage.cancel_like_first_trend()
        cancel_like_num = self.newestpage.get_after_cancel_like_num()
        assert origin_like_num != after_like_num and origin_like_num == cancel_like_num

    def test_c_collect_trend(self):
        """测试收藏动态"""
        self.recommendpage.switch_newest()
        sleep(1)
        self.newestpage.click_first_trend()
        self.newestpage.first_trend_collect()
        sleep(0.3)
        origin = self.newestpage.get_first_trend_content()
        self.newestpage.trend_detail_back()
        self.recommendpage.switch_mine()
        self.minepage.click_menu()
        self.minepage.click_my_collect()
        actual = self.minepage.get_first_collect_content()
        assert origin == actual

    def test_d_cancel_collect_trend(self):
        """测试取消收藏动态"""
        self.recommendpage.switch_newest()
        sleep(1)
        self.newestpage.click_first_trend()
        self.newestpage.first_trend_collect()
        assert self.newestpage.is_text_toast_exist('取消收藏成功')

    def test_e_delete_trend(self):
        """测试删除动态"""
        self.recommendpage.switch_newest()
        origin = self.newestpage.get_first_trend_content()
        self.newestpage.delete_first_trend()
        new = self.newestpage.get_first_trend_content()
        assert origin != new

    @unittest.skip('由于举报成功toast无法捕捉，跳过用例')
    def test_f_report_trend(self):
        """测试举报动态"""
        self.recommendpage.switch_newest()
        self.newestpage.report_third_trend()
        assert self.newestpage.is_text_toast_exist('举报成功')


if __name__ == '__main__':
    unittest.main(__file__)